﻿using Microsoft.WindowsAzure.MobileServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using WCFServiceModel;
using WCFServiceModel.Model;
using WCFServiceModel.Model.Enums;
namespace WCFServiceModel.Model
{
    public class Action
    {

        private string _id;
        [DataMember]
        public string Id
        {
            get { return _id; }
            set { _id = value; }
        }
        [DataMember]
        public string ActionType
        {
            get;
            set;
        }
        private string _idControl;
        [DataMember]
        public string IdControl
        {
            get { return _idControl; }
            set { _idControl = value; }
        }
        private int _count;
        [DataMember]
        public int Count
        {
            get { return _count; }
            set { _count = value; }
        }
        private string _baseControl;
        [DataMember]
        public string BaseControl
        {
            get { return _baseControl; }
            set { _baseControl = value; }
        }
        private string _idSession;
        [DataMember]
        public string IdSession
        {
            get { return _idSession; }
            set { _idSession = value; }
        }

        private double _x;
           [DataMember]
        public double X
        {
            get { return _x; }
            set { _x = value; }
        }
        private double _y;
           [DataMember]
        public double Y
        {
            get { return _y; }
            set { _y = value; }
        }

        private IMobileServiceTable<Action> actionTable = ServiceManager.getCurrentContext().GetTable<Action>();
        public Action(string idSession, string baseControl, string idControl, ActionType action)
        {
            BaseControl = baseControl;
            IdControl = idControl;
            this.ActionType = Enum.GetName(typeof(ActionType), action);
            InsertAction();
        }
        public Action(string idSession, string baseControl, string idControl, ActionType action,double x,double y)
        {
            BaseControl = baseControl;
            IdControl = idControl;
            this.ActionType = Enum.GetName(typeof(ActionType), action);
            X = x;
            Y = y;
            InsertAction();
        }

        //add business logic
        private async void InsertAction()
        {
            await actionTable.InsertAsync(this);
        }


    }
}